using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Formboard.Resources;

namespace Formboard
{
	public class CalculBoard
	{
		private Cell[,]  board;
		public int size; //size is always +2 because of the borders
		CalculMove current;

		public CalculBoard (int boardSize)
		{
			size = boardSize + 2;
			this.board = new Cell[size, size];
			for (int i = 0; i < size; i++) {
				for (int j = 0; j < size; j++) {
					this.board [i, j] = new Cell (i, j);
					if (i == 0 || i == (size - 1) || j == 0 || j == (size - 1)) {
						getCell (i, j).Value = EnumCell.Edge;
					} else {
						getCell (i, j).Value = EnumCell.Free;
					}
				}
			}
			fillNeighbor ();
		}

		public Cell getCell (int i, int j)
		{
			return this.board [i, j];
		}

		public void fillNeighbor ()
		{
			for (int i = 1; i < (size-1); i++) {
				for (int j = 1; j < (size-1); j++) {
					getCell (i, j).addNeighbor (this.board [i - 1, j]);
					getCell (i, j).addNeighbor (this.board [i, j - 1]);
					getCell (i, j).addNeighbor (this.board [i + 1, j]);
					getCell (i, j).addNeighbor (this.board [i, j + 1]);
				}
			}
		}

		public void Board_Reconstruction (List<Move> moveList)
		{
			bool blacktoplay = true;
			for (int i = 0; i < moveList.Count(); i++) {
				if (blacktoplay) {
					current = new CalculMove (this, EnumCell.Black, moveList [i].Row + 1, moveList [i].Column + 1);
					blacktoplay = false;
				} else {
					current = new CalculMove (this, EnumCell.White, moveList [i].Row + 1, moveList [i].Column + 1);
					blacktoplay = true;
				}
			}
		}

	}
}
